package org.example;

import org.example.vo.VcodeProperties;
import org.example.web.VcodeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Hello world!
 *
 */
@AutoConfiguration
@ComponentScan("org.example")
@ConditionalOnProperty(prefix = "vcode",name = "enable")
public class VcodeApp implements WebMvcConfigurer {

    @Autowired
    VcodeProperties vcodeProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new VcodeInterceptor());
        registration.addPathPatterns(vcodeProperties.getUrls());
    }
}
